home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Misc / InstallerNG / developer / gui / example / igui_AskNumber.c < prev    next >
C/C++ Source or Header  |  1999-10-31  |  4KB  |  138 lines

  1.  
  2. #include "includes.h"
  3. #include "installergui_data.h"
  4.  
  5. /********************************************************************
  6.  *
  7.  *  DESCRIPTION
  8.  *
  9.  *  set up a simple panel, which asks the user for a number. this
  10.  *  may be done by a string gadget or (as additional feature!) as
  11.  *  a slider when the range is known. you can check for the range
  12.  *  by testing the localenv->fe_RangeSet entry and you can get
  13.  *  the lower and upper bounds by reading the localenv->fe_Range[0]
  14.  *  and localenv->fe_Range[1] entries. this function must not return
  15.  *  numbers out of range (if range is set!)
  16.  *
  17.  *  IN:  application - pointer to the private application structure
  18.  *       localenv - the local environment of the related ASKNUMBER function
  19.  *
  20.  *  OUT: the valid (!!) number
  21.  *
  22.  */
  23.  
  24. /********************************************************************
  25.  *
  26.  *  STATIC
  27.  *
  28.  */
  29.  
  30. /********************************************************************
  31.  *
  32.  *  EXTERN
  33.  *
  34.  */
  35.  
  36. /********************************************************************
  37.  *
  38.  *  PUBLIC
  39.  *
  40.  */
  41.  
  42. /********************************************************************
  43.  *
  44.  *  CODE
  45.  *
  46.  */
  47.  
  48. long __asm igui_AskNumber(register __a0 APTR application,
  49.                           register __a1 struct FunctionEnvironment *localenv)
  50. {
  51.   #ifdef DEBUG
  52.   DEBUG_MAKRO
  53.   #endif
  54.  
  55.   {
  56.     struct Application *app = (struct Application *) application;
  57.  
  58.     // the number
  59.     long number = 0;
  60.  
  61.     // the mui objects
  62.     APTR asknum, numobj;
  63.  
  64.     // maybe we have to create a new prompt?!
  65.     char *prompt = (char *) localenv->fe_Prompt;
  66.  
  67.     // if the user specified a RANGE, then localenv->fe_RangeSet is TRUE
  68.     // and localenv->fe_Range[0] and localenv->fe_Range[1] hold the values
  69.     // in this case, we have to append the known "Valid range is..." string
  70.     // to the default prompt parameter!
  71.     if (localenv->fe_RangeSet)
  72.     {
  73.       long args[3];
  74.  
  75.       // korrect the default value, if it is out of range
  76.       localenv->fe_Default = sav_RangeNumber(localenv->fe_Default, localenv->fe_Range[0], localenv->fe_Range[1]);
  77.  
  78.       args[0] = localenv->fe_Prompt;
  79.       args[1] = localenv->fe_Range[0];
  80.       args[2] = localenv->fe_Range[1];
  81.  
  82.       if (prompt = sav_StringF2(app->app_Texts[ASKNUM_RANGE], &args)) { }
  83.       else                                                            { app->app_Error = GUIERROR_OUT_OF_MEMORY; return(number); }
  84.     }
  85.  
  86.     //create the object
  87.     asknum = GroupObject,
  88.                Child, HVSpace,
  89.                Child, TextObject,
  90.                  MUIA_Frame, MUIV_Frame_None,
  91.                  MUIA_Text_Contents, prompt,
  92.                  MUIA_Text_SetMin, TRUE,
  93.                  MUIA_Text_PreParse, "\33c",
  94.                End,
  95.                Child, numobj = StringObject,
  96.                  MUIA_Frame, MUIV_Frame_String,
  97.                  MUIA_String_Integer, localenv->fe_Default,
  98.                  MUIA_String_Accept, "0123456789",
  99.                  MUIA_String_Format, MUIV_String_Format_Center,
  100.                End,
  101.                Child, HVSpace,
  102.              End;
  103.  
  104.     // maybee BACK (if specified) or respect the swing mode
  105.     if (localenv->fe_Back)         { guistuff_SetBackButton(app, TRUE); }
  106.     else if (!app->app_SWING_Mode) { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }
  107.  
  108.     //
  109.     if (guistuff_NewContent(app, asknum))
  110.     {
  111.       // we have to wait, until the correct number was entered!
  112.       while(TRUE)
  113.       {
  114.         igui_WaitApp(app);
  115.         if (igui_QuitApp(app)) { break; }
  116.         else
  117.         {
  118.           // get the number an check for its range (if we have to)!
  119.           GetAttr(MUIA_String_Integer, numobj, (ULONG *) &number);
  120.           if (localenv->fe_RangeSet)
  121.           {
  122.             if (number < localenv->fe_Range[0] || number > localenv->fe_Range[1]) { DisplayBeep(NULL); }
  123.             else                                                                  { break; }
  124.           }
  125.         }
  126.       }
  127.     }
  128.     else { /* NO GUI OBJECT */ }
  129.  
  130.     //
  131.     if (localenv->fe_Back) { guistuff_SetBackButton(app, FALSE); }
  132.  
  133.     igui_EmptyPanel(app);
  134.     return(number);
  135.   }
  136. }
  137.  
  138.